# -*- coding: utf-8 -*-
import unittest
from graphs.matrixgraph import MatrixGraph


class MatrixGraphTest(unittest.TestCase):

    def setUp(self):
        self.graph = MatrixGraph()

    def test_add_two_vertices(self):
        self.graph.add_vertex('V1')
        self.graph.add_vertex('V2')

        self.assertEqual(2, self.graph.vertex_count())

    def test_add_fifteen_vertices(self):
        n = 15
        for i in range(n):
            name = 'V' + str(i)
            self.graph.add_vertex(name)

        self.assertEqual(n, self.graph.vertex_count())

    def test_add_vertices_add_edge_check_edge(self):
        n = 15
        for i in range(n):
            name = 'V' + str(i)
            self.graph.add_vertex(name)

        self.graph.add_edge('V4', 'V5', 1)

        weight = self.graph.get_edge('V4', 'V5')

        self.assertEqual(1, weight)

    def test_load(self):
        self.graph.load('inputs/test1.txt')

        self.assertEqual(7, self.graph.vertex_count())

        self.assertEqual(1, self.graph.get_edge('A', 'B'))
        self.assertEqual(1, self.graph.get_edge('A', 'C'))
        self.assertEqual(1, self.graph.get_edge('A', 'D'))

        self.assertEqual(1, self.graph.get_edge('B', 'A'))
        self.assertEqual(1, self.graph.get_edge('B', 'E'))

        self.assertEqual(1, self.graph.get_edge('C', 'A'))
        self.assertEqual(1, self.graph.get_edge('C', 'F'))

        self.assertEqual(1, self.graph.get_edge('D', 'A'))

        self.assertEqual(1, self.graph.get_edge('E', 'B'))
